﻿export function init(toolboxId, dotNetHelper) {
    dispose(toolboxId);
    window.SORTABLE_INSTANCES ??= {};
    window.SORTABLE_INSTANCES[toolboxId] = new Sortable(document.getElementById(toolboxId), {
        sort: false,
        draggable: ".component-tool",
        group: {
            name: 'detail-view-editor',
            pull: 'clone',
            put: false,
        },
        setData: function (dataTransfer, dragEl) {
            const dragData = dragEl.getAttribute('drag-data');
            if (dragData) {
                dataTransfer.setData('Text', dragData);
            }
        }
    });
}

export function dispose(toolboxId) {
    if (window.SORTABLE_INSTANCES && window.SORTABLE_INSTANCES[toolboxId]) {
        window.SORTABLE_INSTANCES[toolboxId].destroy();
        delete window.SORTABLE_INSTANCES[toolboxId];
    }
}